package day11;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class XMLSearch {
    public static void main(String[] args) throws DocumentException {
        //根据姓名来找学生信息
        Scanner input=new Scanner(System.in);
        System.out.println("查找的姓名：");
        String name=input.next();
        SAXReader reader=new SAXReader();
        Document document = reader.read(new File("E:\\java_workspace\\IdeaProjects\\kgc76\\javaadv\\src\\day10\\java76.xml"));
       List<Element> list = document.selectNodes("/javaclass/student[name='" + name + "']");
     //   List<Element> list = document.selectNodes("/javaclass/student[contains(name,'" + name + "')]");
        if(list.size()==0){
            System.out.println("查无此人");
            return;
        }
        for(Element e:list){
            String no = e.attributeValue("no");
            String sex = e.attributeValue("sex");
            String ename=e.selectSingleNode("name").getText();
            String age=e.selectSingleNode("age").getText();
            String phone=e.selectSingleNode("phone").getText();
            String goodAt=e.selectSingleNode("goodAt").getText().trim();

            System.out.printf("%s %s %s %s %s %s\n",no,sex,ename,age,phone,goodAt);
        }
    }
}
